package algorithm;

public class ListNode {

    public int data;

    public ListNode next;

    public ListNode(int data) {
        this.data = data;
    }

    public ListNode(int data, ListNode next) {
        this.data = data;
        this.next = next;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        ListNode temp = this;
        while (temp != null) {
            sb.append(temp.data);
            if (temp.next != null) {
                sb.append("->");
            }
            temp = temp.next;
        }
        return sb.toString();
    }
}
